<?php

/**
 * Mail form base class.
 *
 * @method Mail getObject() Returns the current form's model object
 *
 * @package    25Mails
 * @subpackage form
 * @author     fabio.lorenzini@25solutions.com
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseMailForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'mail_id'      => new sfWidgetFormInputHidden(),
      'campaign_id'  => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Campaign'), 'add_empty' => false)),
      'template_id'  => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Template'), 'add_empty' => false)),
      'recipient_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Recipient'), 'add_empty' => false)),
      'sending_date' => new sfWidgetFormDateTime(),
      'status'       => new sfWidgetFormChoice(array('choices' => array('SENDING' => 'SENDING', 'SENT' => 'SENT', 'ERROR' => 'ERROR'))),
      'notes'        => new sfWidgetFormTextarea(),
      'created_at'   => new sfWidgetFormDateTime(),
      'updated_at'   => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'mail_id'      => new sfValidatorChoice(array('choices' => array($this->getObject()->get('mail_id')), 'empty_value' => $this->getObject()->get('mail_id'), 'required' => false)),
      'campaign_id'  => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Campaign'))),
      'template_id'  => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Template'))),
      'recipient_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Recipient'))),
      'sending_date' => new sfValidatorDateTime(array('required' => false)),
      'status'       => new sfValidatorChoice(array('choices' => array(0 => 'SENDING', 1 => 'SENT', 2 => 'ERROR'), 'required' => false)),
      'notes'        => new sfValidatorString(array('required' => false)),
      'created_at'   => new sfValidatorDateTime(),
      'updated_at'   => new sfValidatorDateTime(),
    ));

    $this->widgetSchema->setNameFormat('mail[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'Mail';
  }

}
